/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.minierp.bean.OrderParameterCarrier;
import com.minierp.bean.PurchaseBillBean;
import com.minierp.bean.PurchaseBillItemBean;
import com.minierp.bean.PurchaseDetailBean;
import com.minierp.bean.QueryParameterBean;
import com.minierp.bean.QueryResult;
import com.minierp.bean.UserBean;
import com.minierp.bean.UserStatus;
import com.minierp.dao.AdjustBillDao;
import com.minierp.dao.BankAccountBalanceDao;
import com.minierp.dao.BankAccountDao;
import com.minierp.dao.BankAccountDetailDao;
import com.minierp.dao.CodeRuleDao;
import com.minierp.dao.FinanceDetailDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.PayBillDao;
import com.minierp.dao.ProductDao;
import com.minierp.dao.ProductTypeDao;
import com.minierp.dao.PurchaseBillDao;
import com.minierp.dao.PurchaseBillItemDao;
import com.minierp.dao.QueryDao;
import com.minierp.dao.StockBalanceDao;
import com.minierp.dao.StockDao;
import com.minierp.dao.StorehouseDao;
import com.minierp.dao.TallySetDao;
import com.minierp.err.NotAllowException;
import com.minierp.err.PermissionDennyException;
import com.minierp.err.StockNoEnoughException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.EncInterceptorHelper;
import com.minierp.helper.EncPurchaseBillMACtrHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.BankAccount;
import com.minierp.model.EnterpriseInfo;
import com.minierp.model.Establishment;
import com.minierp.model.Product;
import com.minierp.model.PurchaseBill;
import com.minierp.model.PurchaseBillExt;
import com.minierp.model.PurchaseBillItem;
import com.minierp.model.Storehouse;
import com.minierp.model.TallySet;
import com.minierp.service.PurchaseBillService;
import com.minierp.view.PurchaseBillListExcelView;
import com.minierp.view.PurchaseBillListForAccountExcelView;
import com.minierp.view.PurchaseBillListForPayExcelView;
import com.minierp.view.PurchaseCountExcelView;
import com.minierp.view.PurchaseDetailExcelView;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class PurchaseBillMACtr extends MultiActionController {
	private PurchaseBillDao purchaseBillDao;
	private PurchaseBillItemDao purchaseBillItemDao;
	private ProductDao productDao;
	private StockDao stockDao;
	private StockBalanceDao stockBalanceDao;
	private BankAccountDao bankAccountDao;
	private StorehouseDao storehouseDao;
	private BankAccountBalanceDao bankAccountBalanceDao;
	private BankAccountDetailDao bankAccountDetailDao;
	private PayBillDao payBillDao;
	private AdjustBillDao adjustBillDao;
	private ProductTypeDao productTypeDao;
	private TallySetDao tallySetDao;
	private QueryDao queryDao;
	private CodeRuleDao codeRuleDao;
	private FinanceDetailDao financeDetailDao;
	private IdGenerator idGenerator;
	private PurchaseBillService purchaseBillService;
	private DataSource dataSource;
	private String dialogSuccessView;
	private String listForExamineView;
	private String infoForExamineView;
	private String listForUnExamineView;
	private String infoForUnExamineView;
	private String listForStocView;
	private String infoForStocView;
	private String listForUnStocView;
	private String infoForUnStocView;
	private String listForCancelView;
	private String infoForCancelView;
	private String searchResultView;
	private String infoForPrintView;
	private String detailSearchResultView;
	private String countSearchResultView;
	private String listForAccountFormView;
	private String listForAccountView;
	private String listForPayView;
	private String relBillListView;
	private String relBillCancelView;
	private String itemListForSelectView;
	private String itemListForEstablishmentView;
	private String uploadFormView;

	public String getListForStocView() {
		return this.listForStocView;
	}

	public void setListForStocView(String listForStocView) {
		this.listForStocView = listForStocView;
	}

	public String getInfoForStocView() {
		return this.infoForStocView;
	}

	public void setInfoForStocView(String infoForStocView) {
		this.infoForStocView = infoForStocView;
	}

	public String getListForUnStocView() {
		return this.listForUnStocView;
	}

	public void setListForUnStocView(String listForUnStocView) {
		this.listForUnStocView = listForUnStocView;
	}

	public String getInfoForUnStocView() {
		return this.infoForUnStocView;
	}

	public void setInfoForUnStocView(String infoForUnStocView) {
		this.infoForUnStocView = infoForUnStocView;
	}

	public String getUploadFormView() {
		return this.uploadFormView;
	}

	public void setUploadFormView(String uploadFormView) {
		this.uploadFormView = uploadFormView;
	}

	public String getItemListForSelectView() {
		return this.itemListForSelectView;
	}

	public void setItemListForSelectView(String itemListForSelectView) {
		this.itemListForSelectView = itemListForSelectView;
	}

	public String getRelBillListView() {
		return this.relBillListView;
	}

	public void setRelBillListView(String relBillListView) {
		this.relBillListView = relBillListView;
	}

	public String getRelBillCancelView() {
		return this.relBillCancelView;
	}

	public void setRelBillCancelView(String relBillCancelView) {
		this.relBillCancelView = relBillCancelView;
	}

	public PurchaseBillDao getPurchaseBillDao() {
		return this.purchaseBillDao;
	}

	public void setPurchaseBillDao(PurchaseBillDao purchaseBillDao) {
		this.purchaseBillDao = purchaseBillDao;
	}

	public PurchaseBillItemDao getPurchaseBillItemDao() {
		return this.purchaseBillItemDao;
	}

	public void setPurchaseBillItemDao(PurchaseBillItemDao purchaseBillItemDao) {
		this.purchaseBillItemDao = purchaseBillItemDao;
	}

	public PurchaseBillService getPurchaseBillService() {
		return this.purchaseBillService;
	}

	public void setPurchaseBillService(PurchaseBillService purchaseBillService) {
		this.purchaseBillService = purchaseBillService;
	}

	public String getSearchResultView() {
		return this.searchResultView;
	}

	public void setSearchResultView(String searchResultView) {
		this.searchResultView = searchResultView;
	}

	public String getDialogSuccessView() {
		return this.dialogSuccessView;
	}

	public void setDialogSuccessView(String dialogSuccessView) {
		this.dialogSuccessView = dialogSuccessView;
	}

	public String getInfoForCancelView() {
		return this.infoForCancelView;
	}

	public void setInfoForCancelView(String infoForCancelView) {
		this.infoForCancelView = infoForCancelView;
	}

	public String getInfoForExamineView() {
		return this.infoForExamineView;
	}

	public void setInfoForExamineView(String infoForExamineView) {
		this.infoForExamineView = infoForExamineView;
	}

	public String getInfoForUnExamineView() {
		return this.infoForUnExamineView;
	}

	public void setInfoForUnExamineView(String infoForUnExamineView) {
		this.infoForUnExamineView = infoForUnExamineView;
	}

	public String getListForCancelView() {
		return this.listForCancelView;
	}

	public void setListForCancelView(String listForCancelView) {
		this.listForCancelView = listForCancelView;
	}

	public String getListForExamineView() {
		return this.listForExamineView;
	}

	public void setListForExamineView(String listForExamineView) {
		this.listForExamineView = listForExamineView;
	}

	public String getListForUnExamineView() {
		return this.listForUnExamineView;
	}

	public void setListForUnExamineView(String listForUnExamineView) {
		this.listForUnExamineView = listForUnExamineView;
	}

	public ProductDao getProductDao() {
		return this.productDao;
	}

	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}

	public ModelAndView handleItemListForSelect(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.itemListForSelectView);
		String searchType = request.getParameter("search_type");
		long tsId = Long.parseLong(request.getParameter("ts_id"));
		long providerId = Long.parseLong(request.getParameter("id"));
		String billType = request.getParameter("bill_type");
		String proName = "";
		String proCode = "";
		long ptId = 0L;
		mv.addObject("providerId", request.getParameter("id"));
		mv.addObject("billType", request.getParameter("bill_type"));
		mv.addObject("tsId", request.getParameter("ts_id"));
		mv.addObject("proName", request.getParameter("pro_name"));
		mv.addObject("proCode", request.getParameter("pro_code"));
		mv.addObject("ptId", request.getParameter("pt_id"));
		if (searchType != null && !searchType.equals("")) {
			if (searchType.equals("2")) {
				proName = request.getParameter("pro_name");
			} else {
				String total = request.getParameter("cb_pro_name");
				String perPageNum = request.getParameter("cb_pro_code");
				String pageno = request.getParameter("cb_pt");
				if (total != null && total.equals("1")) {
					proName = request.getParameter("pro_name");
					mv.addObject("cbProName", total);
				}

				if (perPageNum != null && perPageNum.equals("1")) {
					proCode = request.getParameter("pro_code");
					mv.addObject("cbProCode", perPageNum);
				}

				if (pageno != null && pageno.equals("1")) {
					ptId = Long.parseLong(request.getParameter("pt_id"));
					mv.addObject("cbPt", pageno);
				}
			}
		}

		int total1 = this.purchaseBillItemDao.getListForSelectCount(providerId,
				billType, tsId, proName, proCode, ptId);
		int perPageNum1 = EncCommonHelper.getPageSize(request);
		int pageno1 = EncCommonHelper.getCurrentPageIndex(request, total1,
				perPageNum1);
		int startIndex = (pageno1 - 1) * perPageNum1;
		List list = this.purchaseBillItemDao
				.getListForSelect(providerId, billType, tsId, proName, proCode,
						ptId, startIndex, perPageNum1);
		mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total1,
				perPageNum1, pageno1));
		mv.addObject("searchType", searchType);
		mv.addObject("ptList", this.productTypeDao.getList(true));
		return mv;
	}

	public ModelAndView handleListForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForExamineView);
		String searchKey = request.getParameter("search_key");
		String type = request.getParameter("type");
		String tsId = request.getParameter("ts_id");
		if (type != null && type.equals("BUY")) {
			if (!EncCommonHelper.checkPrivilege(request, "PURC_BUY_EXAM")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null && type.equals("BACK")
				&& !EncCommonHelper.checkPrivilege(request, "PURC_BACK_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		}

		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (tsId == null || tsId.equals("")) {
			tsId = String.valueOf(ub.getUser().getDfTsId());
		}

		List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
		long managerId = 0L;
		if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
			managerId = ub.getStaffer().getId();
		}

		Date allowStart = null;
		if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
			allowStart = EncCommonHelper.getEarlDataDate(request);
		}

		int perPageNum = EncCommonHelper.getPageSize(request);
		int total = this.purchaseBillDao.getListCount(type, searchKey, false,
				Long.parseLong(tsId), managerId, ub, allowStart);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
				perPageNum);
		int startIndex = (pageno - 1) * perPageNum;
		List list = this.purchaseBillDao.getList(type, searchKey, false,
				Long.parseLong(tsId), managerId, ub, allowStart, startIndex,
				perPageNum);
		List arr = this.parsePurchaseBill(list);
		mv.addObject("qr", EncCommonHelper.parseQueryResult(arr, total,
				perPageNum, pageno));
		mv.addObject("storehouseList", this.storehouseDao.getList(false));
		mv.addObject("searchKey", searchKey);
		mv.addObject("type", type);
		mv.addObject("tsId", tsId);
		mv.addObject("tsList", tsList);
		return mv;
	}

	public ModelAndView handleInfoForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForExamineView);
		String id = request.getParameter("id");
		this.getPurchaseBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForUnExamineView);
		String searchKey = request.getParameter("search_key");
		String type = request.getParameter("type");
		String tsId = request.getParameter("ts_id");
		if (type != null && type.equals("BUY")) {
			if (!EncCommonHelper.checkPrivilege(request, "PURC_BUY_UN_EXAM")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null
				&& type.equals("BACK")
				&& !EncCommonHelper
						.checkPrivilege(request, "PURC_BACK_UN_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		}

		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (tsId == null || tsId.equals("")) {
			tsId = String.valueOf(ub.getUser().getDfTsId());
		}

		List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
		long managerId = 0L;
		if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
			managerId = ub.getStaffer().getId();
		}

		Date allowStart = null;
		if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
			allowStart = EncCommonHelper.getEarlDataDate(request);
		}

		int perPageNum = EncCommonHelper.getPageSize(request);
		int total = this.purchaseBillDao.getListCount(type, searchKey, true,
				Long.parseLong(tsId), managerId, ub, allowStart);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
				perPageNum);
		int startIndex = (pageno - 1) * perPageNum;
		List list = this.purchaseBillDao.getList(type, searchKey, true,
				Long.parseLong(tsId), managerId, ub, allowStart, startIndex,
				perPageNum);
		List arr = this.parsePurchaseBill(list);
		mv.addObject("qr", EncCommonHelper.parseQueryResult(arr, total,
				perPageNum, pageno));
		mv.addObject("storehouseList", this.storehouseDao.getList(false));
		mv.addObject("searchKey", searchKey);
		mv.addObject("type", type);
		mv.addObject("tsId", tsId);
		mv.addObject("tsList", tsList);
		return mv;
	}

	public ModelAndView handleInfoForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForUnExamineView);
		String id = request.getParameter("id");
		this.getPurchaseBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForCancelView);
		String searchKey = request.getParameter("search_key");
		String type = request.getParameter("type");
		String tsId = request.getParameter("ts_id");
		if (type != null && type.equals("BUY")) {
			if (!EncCommonHelper.checkPrivilege(request, "PURC_BUY_CANC")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null && type.equals("BACK")
				&& !EncCommonHelper.checkPrivilege(request, "PURC_BACK_CANC")) {
			throw new PermissionDennyException("Permission Denny");
		}

		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (tsId == null || tsId.equals("")) {
			tsId = String.valueOf(ub.getUser().getDfTsId());
		}

		List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
		long managerId = 0L;
		if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
			managerId = ub.getStaffer().getId();
		}

		Date allowStart = null;
		if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
			allowStart = EncCommonHelper.getEarlDataDate(request);
		}

		int perPageNum = EncCommonHelper.getPageSize(request);
		int total = this.purchaseBillDao.getListForCancelCount(type, searchKey,
				Long.parseLong(tsId), managerId, ub, allowStart);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
				perPageNum);
		int startIndex = (pageno - 1) * perPageNum;
		List list = this.purchaseBillDao.getListForCancel(type, searchKey,
				Long.parseLong(tsId), managerId, ub, allowStart, startIndex,
				perPageNum);
		mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
				perPageNum, pageno));
		mv.addObject("storehouseList", this.storehouseDao.getList(false));
		mv.addObject("searchKey", searchKey);
		mv.addObject("type", type);
		mv.addObject("tsId", tsId);
		mv.addObject("tsList", tsList);
		return mv;
	}

	public ModelAndView handleInfoForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForCancelView);
		String id = request.getParameter("id");
		this.getPurchaseBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String idStr = request.getParameter("id_str");
		String flag = request.getParameter("flag");
		boolean examined = false;
		if (flag != null && flag.equals("1")) {
			examined = true;
		}

		String[] arr = idStr.split(";");
		boolean num = false;
		String msg;
		int se;
		byte arg17;
		if (!examined) {
			try {
				for (se = 0; se < arr.length; ++se) {
					this.purchaseBillService.txUnExamine(request,
							Long.parseLong(arr[se]), this.purchaseBillDao,
							this.purchaseBillItemDao,
							this.bankAccountBalanceDao,
							this.bankAccountDetailDao, this.stockDao,
							this.stockBalanceDao, this.idGenerator,
							this.financeDetailDao, ub);
				}

				msg = "反审核成功";
			} catch (StockNoEnoughException arg14) {
				msg = arg14.getMessage();
			} catch (NotAllowException arg15) {
				msg = arg15.getMessage();
			} catch (CannotAcquireLockException arg16) {
				msg = "事务冲突故障，请重新操作。";
			}

			arg17 = 1;
		} else {
			try {
				for (se = 0; se < arr.length; ++se) {
					this.purchaseBillService.txExamine(request,
							Long.parseLong(arr[se]), this.purchaseBillDao,
							this.purchaseBillItemDao, this.payBillDao,
							this.adjustBillDao, this.bankAccountBalanceDao,
							this.stockDao, this.stockBalanceDao,
							this.idGenerator, ub);
				}

				msg = "审核成功";
			} catch (StockNoEnoughException arg11) {
				msg = arg11.getMessage();
			} catch (NotAllowException arg12) {
				msg = arg12.getMessage();
			} catch (CannotAcquireLockException arg13) {
				msg = "事务冲突故障，请重新操作。";
			}

			arg17 = 1;
		}

		mv.addObject("returnValue", String.valueOf(arg17));
		EncCommonHelper.setAlertMessage(request, msg);
		return mv;
	}

	public ModelAndView handleCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String id = request.getParameter("id");
		String reason = request.getParameter("reason");
		String msg = "";

		try {
			msg = this.purchaseBillService.txCancel(request,
					Long.parseLong(id), reason, this.purchaseBillDao,
					this.purchaseBillItemDao, this.bankAccountBalanceDao,
					this.bankAccountDetailDao, this.stockDao,
					this.stockBalanceDao, this.idGenerator,
					this.financeDetailDao, ub);
		} catch (StockNoEnoughException arg8) {
			msg = arg8.getMessage();
		} catch (CannotAcquireLockException arg9) {
			msg = "事务冲突故障，请重新操作。";
		}

		mv.addObject("returnValue", id);
		EncCommonHelper.setAlertMessage(request, msg);
		return mv;
	}

	public ModelAndView handleSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String type = request.getParameter("type");
		if (type != null && type.equals("BUY")) {
			if (!EncCommonHelper.checkPrivilege(request, "PURC_BUY_SEAR")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null && type.equals("BACK")
				&& !EncCommonHelper.checkPrivilege(request, "PURC_BACK_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		}

		ModelAndView mv = new ModelAndView(this.searchResultView);
		String contentType = request.getParameter("content_type");
		QueryParameterBean b = EncPurchaseBillMACtrHelper.handleSearchResult(
				request, this.dataSource);
		String[] countObjs = new String[]{"sum(b.cost)", "sum(b.imprest)",
				"sum(be.paiedCost)", "sum(be.adjustCost)"};
		if (contentType != null && contentType.equals("EXCEL")) {
			HashMap ub2 = new HashMap();
			QueryResult ent2 = this.queryDao.doQuery(b.getQParas(),
					b.getOParas(), (String[]) null, b.getShortNameMap(),
					b.getRetObjs(), countObjs);
			ub2.put("list", ent2.getList());
			Object[] objs = ent2.getExtCount();
			ub2.put("costTotal", objs[0]);
			ub2.put("imprestTotal", objs[1]);
			ub2.put("payTotal", objs[2]);
			ub2.put("adjustTotal", objs[3]);
			ub2.put("stoList", this.storehouseDao.getList(false));
			PurchaseBillListExcelView v = new PurchaseBillListExcelView();
			return new ModelAndView(v, ub2);
		} else {
			QueryResult ub = this.queryDao.doQuery(b.getCurrentPage(),
					b.getPageSize(), b.getQParas(), b.getOParas(),
					(String[]) null, b.getShortNameMap(), b.getRetObjs(),
					countObjs);
			mv.addAllObjects(b.getParameters());
			mv.addObject("qr", ub);
			Object[] ent = ub.getExtCount();
			mv.addObject("costTotal", ent[0]);
			mv.addObject("imprestTotal", ent[1]);
			mv.addObject("payTotal", ent[2]);
			mv.addObject("adjustTotal", ent[3]);
			mv.addObject("stoList", this.storehouseDao.getList(false));
			UserBean ub1 = EncCommonHelper.getCurrentUserAccount(request);
			EnterpriseInfo ent1 = EncCommonHelper.getEnterpriseInfo(request);
			if (ent1.getStorTs().equals("Y")) {
				mv.addObject("myStoList", this.storehouseDao.getList(ub1));
			} else {
				mv.addObject("myStoList", this.storehouseDao.getList(true));
			}

			mv.addObject("tsList",
					PageHelper.getTallySetList(this.tallySetDao, ub1));
			mv.addObject("printId", request.getParameter("print_id"));
			mv.addObject("printBill", request.getParameter("print_bill"));
			mv.addObject("printDetail", request.getParameter("print_detail"));
			return mv;
		}
	}

	public ModelAndView handleGetPurcForPay(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String clientId = request.getParameter("est_id");
		String tsId = request.getParameter("ts_id");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		String startDateStr = request.getParameter("start_date");
		String endDateStr = request.getParameter("end_date");
		String billType = request.getParameter("bill_type");
		String parseBack = request.getParameter("parse_back");
		Date startDate = null;
		Date endDate = null;
		if (startDateStr != null && !startDateStr.equals("")) {
			startDate = sf.parse(startDateStr);
		}

		if (endDateStr != null && !endDateStr.equals("")) {
			endDate = sf.parse(EncCommonHelper.getNextDateStr(endDateStr,
					"yyyy-MM-dd"));
		}

		List list = this.purchaseBillDao.getListForPay(
				Long.parseLong(clientId), billType, Long.parseLong(tsId),
				startDate, endDate);
		HashMap map = new HashMap();

		try {
			ArrayList mapper = new ArrayList();
			BigDecimal json = new BigDecimal(0);

			for (int out = 0; out < list.size(); ++out) {
				HashMap item = new HashMap();
				Object[] objs = (Object[]) list.get(out);
				PurchaseBill b = (PurchaseBill) objs[0];
				PurchaseBillExt be = (PurchaseBillExt) objs[1];
				item.put("id", Long.valueOf(b.getId()));
				item.put("code", b.getBillCode());
				item.put("date", sf.format(b.getPurchaseDate()));
				if (parseBack != null && parseBack.equals("1")
						&& b.getBillType().equals("BACK")) {
					item.put("totaCost", json.subtract(b.getCost()));
					item.put(
							"remaCost",
							json.subtract(b.getCost().add(be.getAdjustCost())
									.subtract(be.getPaiedCost())));
				} else {
					item.put("totaCost", b.getCost());
					item.put("remaCost", b.getCost().add(be.getAdjustCost())
							.subtract(be.getPaiedCost()));
				}

				item.put("cont", b.getContent());
				mapper.add(item);
			}

			map.put("items", mapper);
			map.put("status", "OK");
			map.put("errMsg", "");
		} catch (Exception arg20) {
			map.put("status", "ERROR");
			map.put("errMsg", arg20.toString());
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg21 = new ObjectMapper();
		String arg22 = arg21.writeValueAsString(map);
		ServletOutputStream arg23 = response.getOutputStream();
		arg23.write(arg22.getBytes("utf-8"));
		arg23.flush();
		arg23.close();
		return null;
	}

	private List<?> parsePurchaseBill(List<?> list) {
		ArrayList arr = new ArrayList();

		for (int i = 0; i < list.size(); ++i) {
			Object[] objs = (Object[]) list.get(i);
			PurchaseBill purchaseBill = (PurchaseBill) objs[0];
			String estName = (String) objs[1];
			PurchaseBillBean bean = new PurchaseBillBean();
			bean.setPurchaseBill(purchaseBill);
			bean.setProviderName(estName);
			arr.add(bean);
		}

		return arr;
	}

	private PurchaseBillBean getPurchaseBill(ModelAndView mv, long id) {
		PurchaseBill purchaseBill = (PurchaseBill) this.purchaseBillDao.get(
				PurchaseBill.class, id);
		PurchaseBillExt be = (PurchaseBillExt) this.purchaseBillDao.get(
				PurchaseBillExt.class, id);
		PurchaseBillBean form = new PurchaseBillBean();
		if (purchaseBill != null) {
			List itemList = this.purchaseBillItemDao.getList(purchaseBill
					.getId());
			long[] productIds = new long[itemList.size()];

			for (int productList = 0; productList < itemList.size(); ++productList) {
				productIds[productList] = ((PurchaseBillItem) itemList
						.get(productList)).getProductId();
			}

			List arg13 = this.productDao.getList(productIds);
			ArrayList arr = new ArrayList();

			for (int i = 0; i < itemList.size(); ++i) {
				PurchaseBillItemBean bean = new PurchaseBillItemBean();
				PurchaseBillItem item = (PurchaseBillItem) itemList.get(i);
				bean.setPurchaseBillItem(item);
				this.setProductInfo(arg13, bean);
				arr.add(bean);
			}

			form.setPurchaseBill(purchaseBill);
			form.setPurchaseBillExt(be);
			form.setItems(arr);
			this.setPurchaseBillInfo(form);
		}

		mv.addObject("record", form);
		mv.addObject("storehouseList", this.storehouseDao.getList(false));
		mv.addObject("bankAccountList", this.bankAccountDao.getList("", ""));
		return form;
	}

	private void setPurchaseBillInfo(PurchaseBillBean form) {
		PurchaseBill purchaseBill = form.getPurchaseBill();
		if (purchaseBill != null) {
			String offererName = "";
			if (purchaseBill.getProviderId() != 0L) {
				Establishment d = (Establishment) this.purchaseBillDao.get(
						Establishment.class, purchaseBill.getProviderId());
				if (d != null) {
					offererName = d.getEstName();
				}
			}

			form.setProviderName(offererName);
			if (purchaseBill.getTallySetId() != 0L) {
				TallySet d1 = (TallySet) this.purchaseBillDao.get(
						TallySet.class, purchaseBill.getTallySetId());
				if (d1 != null) {
					form.setTallySetName(d1.getTitle());
				}
			}
		}

	}

	public ModelAndView handlePrint(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForPrintView);
		String id = request.getParameter("id");
		PurchaseBillBean bean = this.getPurchaseBill(mv, Long.parseLong(id));
		if (bean != null && bean.getPurchaseBill() != null) {
			if (bean.getPurchaseBill().getBillType().equals("BUY")) {
				mv.addObject("codeRule",
						this.codeRuleDao.get("PURCHASE_BILL_BUY"));
			} else {
				mv.addObject("codeRule",
						this.codeRuleDao.get("PURCHASE_BILL_BACK"));
			}
		}

		return mv;
	}

	private void setProductInfo(List<?> productList, PurchaseBillItemBean cb) {
		String productName = "";
		long productId = cb.getPurchaseBillItem().getProductId();
		if (productId != 0L) {
			for (int j = 0; j < productList.size(); ++j) {
				Product p = (Product) productList.get(j);
				if (p.getId() == productId) {
					productName = p.getProductName();
					cb.setProductCode(p.getProductCode());
					cb.setProductName(productName);
					cb.setUnit(p.getUnit());
					break;
				}
			}
		}

	}

	public ModelAndView handleDetailSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "PURC_DETA")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String contentType = request.getParameter("content_type");
			QueryParameterBean b = EncPurchaseBillMACtrHelper
					.handlePurchaseDetail(request, this.dataSource);
			String[] retObjs = new String[]{"b.billType", "sum(i.cost)"};
			List list = this.queryDao.doQuery(b.getQParas(),
					(OrderParameterCarrier[]) null, new String[]{"b.billType"},
					b.getShortNameMap(), retObjs, (String[]) null).getList();
			String costTotal = "0";
			String buyCost = "0";
			String backCost = "0";
			if (list != null) {
				for (int qr = 0; qr < list.size(); ++qr) {
					Object[] ub = (Object[]) list.get(qr);
					if (ub[0] != null) {
						if (ub[0].toString().equals("BUY")) {
							buyCost = ub[1].toString();
						} else {
							backCost = ub[1].toString();
						}
					}
				}
			}

			costTotal = (new BigDecimal(buyCost)).subtract(
					new BigDecimal(backCost)).toString();
			ModelAndView mv;
			QueryResult arg13;
			if (contentType != null && contentType.equals("EXCEL")) {
				arg13 = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						(String[]) null);
				HashMap arg15 = new HashMap();
				arg15.put("list", this.parseDetailBean(arg13.getList()));
				arg15.put("costTotal", costTotal);
				PurchaseDetailExcelView arg16 = new PurchaseDetailExcelView();
				mv = new ModelAndView(arg16, arg15);
				return mv;
			} else {
				mv = new ModelAndView(this.detailSearchResultView);
				arg13 = this.queryDao.doQuery(b.getCurrentPage(),
						b.getPageSize(), b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						(String[]) null);
				list = this.parseDetailBean(arg13.getList());
				arg13.setList(list);
				mv.addObject("costTotal", costTotal);
				mv.addAllObjects(b.getParameters());
				mv.addObject("qr", arg13);
				UserBean arg14 = EncCommonHelper.getCurrentUserAccount(request);
				EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
				if (ent.getStorTs().equals("Y")) {
					mv.addObject("storehouseList",
							this.storehouseDao.getList(arg14));
				} else {
					mv.addObject("storehouseList",
							this.storehouseDao.getList(true));
				}

				mv.addObject("productTypeList",
						this.productTypeDao.getList(true));
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, arg14));
				return mv;
			}
		}
	}

	public ModelAndView handleCountSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "PURC_COUN")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String contentType = request.getParameter("content_type");
			QueryParameterBean b = EncPurchaseBillMACtrHelper
					.handlePurchaseCount(request, this.dataSource);
			String[] retObjs = new String[]{"b.billType", "sum(i.cost)"};
			List list = this.queryDao.doQuery(b.getQParas(),
					(OrderParameterCarrier[]) null, new String[]{"b.billType"},
					b.getShortNameMap(), retObjs, (String[]) null).getList();
			String costTotal = "0";
			String buyCost = "0";
			String backCost = "0";
			if (list != null) {
				for (int qr = 0; qr < list.size(); ++qr) {
					Object[] ub = (Object[]) list.get(qr);
					if (ub[0] != null) {
						if (ub[0].toString().equals("BUY")) {
							buyCost = ub[1].toString();
						} else {
							backCost = ub[1].toString();
						}
					}
				}
			}

			costTotal = (new BigDecimal(buyCost)).subtract(
					new BigDecimal(backCost)).toString();
			ModelAndView mv;
			QueryResult arg16;
			if (contentType != null && contentType.equals("EXCEL")) {
				arg16 = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						b.getGParas(), b.getShortNameMap(), b.getRetObjs(),
						(String[]) null);
				HashMap arg18 = new HashMap();
				String arg19 = request.getParameter("search_type");
				String cbPurDate = request.getParameter("cb_pur_date");
				String searchTime = "";
				if (arg19 == null || arg19.equals("") || arg19.equals("2")
						|| cbPurDate != null && cbPurDate.equals("1")) {
					searchTime = b.getParameters("startDate") + " 至 "
							+ b.getParameters("endDate");
				}

				arg18.put("list", this.parseCountBean(arg16.getList()));
				arg18.put("costTotal", costTotal);
				arg18.put("searchTime", searchTime);
				PurchaseCountExcelView v = new PurchaseCountExcelView();
				mv = new ModelAndView(v, arg18);
				return mv;
			} else {
				mv = new ModelAndView(this.countSearchResultView);
				arg16 = this.queryDao.doQuery(b.getCurrentPage(),
						b.getPageSize(), b.getQParas(), b.getOParas(),
						b.getGParas(), b.getShortNameMap(), b.getRetObjs(),
						(String[]) null);
				list = this.parseCountBean(arg16.getList());
				arg16.setList(list);
				mv.addObject("costTotal", costTotal);
				mv.addAllObjects(b.getParameters());
				mv.addObject("qr", arg16);
				UserBean arg17 = EncCommonHelper.getCurrentUserAccount(request);
				EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
				if (ent.getStorTs().equals("Y")) {
					mv.addObject("storehouseList",
							this.storehouseDao.getList(arg17));
				} else {
					mv.addObject("storehouseList",
							this.storehouseDao.getList(true));
				}

				mv.addObject("productTypeList",
						this.productTypeDao.getList(true));
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, arg17));
				return mv;
			}
		}
	}

	private List<?> parseDetailBean(List<?> list) {
		ArrayList arr = new ArrayList();

		for (int i = 0; i < list.size(); ++i) {
			Object[] objs = (Object[]) list.get(i);
			PurchaseBill b = (PurchaseBill) objs[0];
			PurchaseBillItem item = (PurchaseBillItem) objs[1];
			String provName = (String) objs[2];
			PurchaseDetailBean bean = new PurchaseDetailBean();
			bean.setAmount(item.getAmount());
			bean.setBillCode(b.getBillCode());
			bean.setBillDate(b.getPurchaseDate());
			bean.setBillType(b.getBillType());
			bean.setCost(item.getCost());
			Product pro = (Product) this.purchaseBillDao.get(Product.class,
					item.getProductId());
			if (pro != null) {
				bean.setProductCode(pro.getProductCode());
				bean.setProductName(pro.getProductName());
				bean.setProductUnit(pro.getUnit());
			}

			bean.setProviderName(provName);
			bean.setUnitPrice(item.getUnitPrice());
			bean.setMark(item.getMark());
			arr.add(bean);
		}

		return arr;
	}

	private List<?> parseCountBean(List<?> list) {
		ArrayList arr = new ArrayList();

		for (int i = 0; i < list.size(); ++i) {
			Object[] objs = (Object[]) list.get(i);
			PurchaseDetailBean bean = new PurchaseDetailBean();
			bean.setAmount(new BigDecimal(objs[2].toString()));
			bean.setBillType(objs[4].toString());
			bean.setCost(new BigDecimal(objs[3].toString()));
			Product pro = (Product) this.purchaseBillDao.get(Product.class,
					Long.parseLong(objs[1].toString()));
			if (pro != null) {
				bean.setProductCode(pro.getProductCode());
				bean.setProductName(pro.getProductName());
				bean.setProductUnit(pro.getUnit());
			}

			String offererName = "";
			long providerId = Long.parseLong(objs[0].toString());
			if (providerId != 0L) {
				Establishment est = (Establishment) this.purchaseBillDao.get(
						Establishment.class, providerId);
				if (est != null) {
					offererName = est.getEstName();
				}
			}

			bean.setProviderName(offererName);
			if (bean.getAmount().compareTo(new BigDecimal(0)) != 0) {
				bean.setUnitPrice(bean.getCost().divide(bean.getAmount(), 2, 4));
			} else {
				bean.setUnitPrice(new BigDecimal(0));
			}

			arr.add(bean);
		}

		return arr;
	}

	public ModelAndView handleListForAccountForm(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "PURC_ACCO")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			Date now = new Date();
			SimpleDateFormat dateSf = new SimpleDateFormat("yyyy-MM-dd");
			String endDate = dateSf.format(now);
			return (new ModelAndView(this.listForAccountFormView)).addObject(
					"end_date", endDate);
		}
	}

	public ModelAndView handleListForAccount(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForAccountView);
		String contentType = request.getParameter("content_type");
		String providerId = request.getParameter("provider_id");
		QueryParameterBean b = EncPurchaseBillMACtrHelper
				.handleListForAccountList(request, this.dataSource);
		mv.addAllObjects(b.getParameters());
		QueryResult qr = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
				(String[]) null, b.getShortNameMap(), b.getRetObjs(),
				(String[]) null);

		for (int list = 0; list < qr.getList().size(); ++list) {
			Object[] costTotal = (Object[]) qr.getList().get(list);
			PurchaseBillItemBean paiedTotal = new PurchaseBillItemBean();
			PurchaseBillItem adjustTotal = (PurchaseBillItem) costTotal[1];
			paiedTotal.setPurchaseBillItem(adjustTotal);
			this.setProductInfo(paiedTotal, adjustTotal.getProductId());
			costTotal[1] = paiedTotal;
		}

		b = EncPurchaseBillMACtrHelper.handleListForAccountCost(request,
				this.dataSource);
		List arg15 = this.queryDao.doQuery(b.getQParas(),
				(OrderParameterCarrier[]) null, b.getGParas(),
				b.getShortNameMap(), b.getRetObjs(), (String[]) null).getList();
		BigDecimal arg16 = new BigDecimal(0);
		BigDecimal arg17 = new BigDecimal(0);
		BigDecimal arg18 = new BigDecimal(0);

		for (int est = 0; est < arg15.size(); ++est) {
			Object[] remainTotal = (Object[]) arg15.get(est);
			if (remainTotal[0] != null) {
				if (remainTotal[3].toString().equals("BUY")) {
					arg16 = arg16
							.add(new BigDecimal(remainTotal[0].toString()));
					arg17 = arg17
							.add(new BigDecimal(remainTotal[1].toString()));
					arg18 = arg18
							.add(new BigDecimal(remainTotal[2].toString()));
				} else {
					arg16 = arg16.subtract(new BigDecimal(remainTotal[0]
							.toString()));
					arg17 = arg17.subtract(new BigDecimal(remainTotal[1]
							.toString()));
					arg18 = arg18.subtract(new BigDecimal(remainTotal[2]
							.toString()));
				}
			}
		}

		Establishment arg19 = (Establishment) this.purchaseBillDao.get(
				Establishment.class, Long.parseLong(providerId));
		BigDecimal arg20 = arg16.add(arg18).subtract(arg17);
		if (contentType != null && contentType.equals("EXCEL")) {
			HashMap map = new HashMap();
			map.put("start_date", request.getParameter("start_date"));
			map.put("end_date", request.getParameter("end_date"));
			map.put("list", qr.getList());
			map.put("est", arg19);
			map.put("costTotal", arg16.toString());
			map.put("paiedTotal", arg17.toString());
			map.put("adjustTotal", arg18.toString());
			map.put("remainTotal", arg20.toString());
			PurchaseBillListForAccountExcelView v = new PurchaseBillListForAccountExcelView();
			return new ModelAndView(v, map);
		} else {
			mv.addObject("qr", qr);
			mv.addObject("est", arg19);
			mv.addObject("costTotal", arg16);
			mv.addObject("paiedTotal", arg17);
			mv.addObject("adjustTotal", arg18);
			mv.addObject("remainTotal", arg20);
			mv.addObject("codeRule", this.codeRuleDao.get("PURCHASE_BILL_BUY"));
			mv.addObject("printId", request.getParameter("print_id"));
			mv.addObject("printBill", request.getParameter("print_bill"));
			mv.addObject("printDetail", request.getParameter("print_detail"));
			return mv;
		}
	}

	public ModelAndView handleListForPay(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "PURC_UN_PAY")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForPayView);
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			String startDateStr = "";
			String endDateStr = "";
			String estName = "";
			String billCode = "";
			String minCost = "";
			String maxCost = "";
			String tsId = "0";
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			Date startDate = null;
			Date endDate = null;
			int total = 0;
			String searchType = request.getParameter("search_type");
			mv.addObject("startDate", request.getParameter("start_date"));
			mv.addObject("endDate", request.getParameter("end_date"));
			mv.addObject("estName", request.getParameter("est_name"));
			mv.addObject("billCode", request.getParameter("bill_code"));
			mv.addObject("minCost", request.getParameter("min_cost"));
			mv.addObject("maxCost", request.getParameter("max_cost"));
			mv.addObject("tsId", request.getParameter("ts_id"));
			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			List cList;
			String contentType;
			if (searchType != null && !searchType.equals("")) {
				if (searchType.equals("2")) {
					startDateStr = request.getParameter("start_date");
					endDateStr = request.getParameter("end_date");
					if (startDateStr != null && !startDateStr.equals("")) {
						startDate = sf.parse(startDateStr);
						if (allowStart != null && allowStart.after(startDate)) {
							startDate = allowStart;
						}
					} else {
						startDate = allowStart;
					}

					if (endDateStr != null && !endDateStr.equals("")) {
						endDate = sf.parse(EncCommonHelper.getNextDateStr(
								endDateStr, "yyyy-MM-dd"));
					}

					cList = this.purchaseBillDao.getListForPayCount("",
							startDate, endDate, "", "", "", 0L, managerId, ub);
				} else {
					String costTotal = request.getParameter("cb_pur_date");
					String paiedTotal = request.getParameter("cb_est");
					String adjustTotal = request.getParameter("cb_bill_code");
					contentType = request.getParameter("cb_cost");
					String perPageNum = request.getParameter("cb_ts");
					if (costTotal != null && costTotal.equals("1")) {
						startDateStr = request.getParameter("start_date");
						endDateStr = request.getParameter("end_date");
						startDate = sf.parse(startDateStr);
						if (allowStart != null && allowStart.after(startDate)) {
							startDate = allowStart;
						}

						endDate = sf.parse(EncCommonHelper.getNextDateStr(
								endDateStr, "yyyy-MM-dd"));
						mv.addObject("cbPurDate", costTotal);
					} else {
						startDate = allowStart;
					}

					if (paiedTotal != null && paiedTotal.equals("1")) {
						estName = request.getParameter("est_name");
						mv.addObject("cbEst", paiedTotal);
					}

					if (adjustTotal != null && adjustTotal.equals("1")) {
						billCode = request.getParameter("bill_code");
						mv.addObject("cbBillCode", adjustTotal);
					}

					if (contentType != null && contentType.equals("1")) {
						minCost = request.getParameter("min_cost");
						maxCost = request.getParameter("max_cost");
						mv.addObject("cbCost", contentType);
					}

					if (perPageNum != null && perPageNum.equals("1")) {
						tsId = request.getParameter("ts_id");
						mv.addObject("cbTs", perPageNum);
					}

					cList = this.purchaseBillDao.getListForPayCount(estName,
							startDate, endDate, billCode, minCost, maxCost,
							Long.parseLong(tsId), managerId, ub);
				}
			} else {
				searchType = "1";
				startDate = allowStart;
				tsId = String.valueOf(ub.getUser().getDfTsId());
				cList = this.purchaseBillDao.getListForPayCount("", allowStart,
						(Date) null, "", "", "", Long.parseLong(tsId),
						managerId, ub);
				mv.addObject("tsId", tsId);
				mv.addObject("cbTs", "1");
			}

			mv.addObject("searchType", searchType);
			BigDecimal arg28 = new BigDecimal(0);
			BigDecimal arg29 = new BigDecimal(0);
			BigDecimal arg30 = new BigDecimal(0);

			for (int arg31 = 0; arg31 < cList.size(); ++arg31) {
				Object[] arg32 = (Object[]) cList.get(arg31);
				if (arg32[0] != null) {
					total += Integer.parseInt(arg32[0].toString());
					if (arg32[4].toString().equals("BUY")) {
						arg28 = arg28.add(new BigDecimal(arg32[1].toString()));
						arg29 = arg29.add(new BigDecimal(arg32[2].toString()));
						arg30 = arg30.add(new BigDecimal(arg32[3].toString()));
					} else {
						arg28 = arg28.subtract(new BigDecimal(arg32[1]
								.toString()));
						arg29 = arg29.subtract(new BigDecimal(arg32[2]
								.toString()));
						arg30 = arg30.subtract(new BigDecimal(arg32[3]
								.toString()));
					}
				}
			}

			contentType = request.getParameter("content_type");
			if (contentType != null && contentType.equals("EXCEL")) {
				HashMap arg34 = new HashMap();
				List arg35 = this.purchaseBillDao.getListForPay(estName,
						startDate, endDate, billCode, minCost, maxCost,
						Long.parseLong(tsId), managerId, ub, 0, total);
				arg34.put("list", arg35);
				arg34.put("remainTotal", arg28.add(arg30).subtract(arg29)
						.toString());
				PurchaseBillListForPayExcelView arg36 = new PurchaseBillListForPayExcelView();
				return new ModelAndView(arg36, arg34);
			} else {
				int arg33 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg33);
				int startIndex = (pageno - 1) * arg33;
				List list = this.purchaseBillDao.getListForPay(estName,
						startDate, endDate, billCode, minCost, maxCost,
						Long.parseLong(tsId), managerId, ub, startIndex, arg33);
				mv.addObject("qr", EncCommonHelper.parseQueryResult(list,
						total, arg33, pageno));
				mv.addObject("tsList", PageHelper.getTallySetList(
						this.tallySetDao,
						EncCommonHelper.getCurrentUserAccount(request)));
				mv.addObject("remainTotal", arg28.add(arg30).subtract(arg29));
				mv.addObject("printId", request.getParameter("print_id"));
				mv.addObject("printBill", request.getParameter("print_bill"));
				mv.addObject("printDetail",
						request.getParameter("print_detail"));
				return mv;
			}
		}
	}

	public ModelAndView handleRelBillList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.relBillListView);
		long id = Long.parseLong(request.getParameter("id"));
		String code = request.getParameter("code");
		String billType = request.getParameter("bill_type");
		mv.addObject("payList", this.payBillDao.getList("PURCHASE", id));
		mv.addObject("adjustList",
				this.adjustBillDao.getList("PURCHASE_BILL", id));
		mv.addObject("code", code);
		mv.addObject("billType", billType);
		return mv;
	}

	public ModelAndView handleRelBillCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.relBillCancelView);
		long id = Long.parseLong(request.getParameter("id"));
		String code = request.getParameter("code");
		String billType = request.getParameter("bill_type");
		mv.addObject("payList", this.payBillDao.getList("PURCHASE", id));
		mv.addObject("adjustList",
				this.adjustBillDao.getList("PURCHASE_BILL", id));
		mv.addObject("code", code);
		mv.addObject("billType", billType);
		return mv;
	}

	private void setProductInfo(PurchaseBillItemBean bean, long productId) {
		Product p = (Product) this.productDao.get(Product.class, productId);
		if (p != null) {
			bean.setProductName(p.getProductName());
			bean.setProductCode(p.getProductCode());
			bean.setUnit(p.getUnit());
		}

	}

	public ModelAndView handleItemListForEstablishment(
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView(this.itemListForEstablishmentView);
		String clientId = request.getParameter("id");
		mv.addObject("id", clientId);
		QueryParameterBean b = EncPurchaseBillMACtrHelper
				.handleItemListForEstablishment(request, this.dataSource);
		BigDecimal costTotal = new BigDecimal(0);
		List list = this.queryDao.doQuery(b.getQParas(),
				(OrderParameterCarrier[]) null, new String[]{"b.billType"},
				b.getShortNameMap(), new String[]{"b.billType", "sum(i.cost)"},
				(String[]) null).getList();

		for (int qr = 0; qr < list.size(); ++qr) {
			Object[] objs = (Object[]) list.get(qr);
			if (objs != null && objs[0] != null) {
				if (objs[0].toString().equals("BUY")) {
					costTotal = costTotal.add((BigDecimal) objs[1]);
				} else {
					costTotal = costTotal.subtract((BigDecimal) objs[1]);
				}
			}
		}

		QueryResult arg9 = this.queryDao.doQuery(b.getCurrentPage(),
				b.getPageSize(), b.getQParas(), b.getOParas(), (String[]) null,
				b.getShortNameMap(), b.getRetObjs(), (String[]) null);
		mv.addObject("qr", arg9);
		mv.addObject("costTotal", costTotal);
		mv.addObject(
				"est",
				this.purchaseBillDao.get(Establishment.class,
						Long.parseLong(clientId)));
		return mv;
	}

	public ModelAndView handleUploadForm(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.uploadFormView);
		String storehouseId = request.getParameter("storehouse_id");
		mv.addObject("storehouseId", storehouseId);
		return mv;
	}

	public ModelAndView handleImportItem(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String fileName = request.getParameter("file_name");
		File file = new File(this.getServletContext().getRealPath(fileName));
		String alertMsg = "";
		Document doc = DocumentHelper.createDocument();
		Element root = doc.addElement("body");
		String productCode = "";
		String amountStr = "";
		String priceStr = "";
		String mark = "";
		BigDecimal zero = new BigDecimal(0);
		BufferedInputStream in = null;

		try {
			in = new BufferedInputStream(new FileInputStream(file));
			HSSFWorkbook format = new HSSFWorkbook(new POIFSFileSystem(in));

			for (int i = 0; i < format.getNumberOfSheets(); ++i) {
				HSSFSheet arg45 = format.getSheetAt(i);

				for (int j = 1; j < arg45.getPhysicalNumberOfRows(); ++j) {
					HSSFRow output = arg45.getRow(j);
					if (output == null) {
						break;
					}

					HSSFCell cell = output.getCell(0);
					productCode = PageHelper.getCellVal(cell, 25);
					cell = output.getCell(3);
					amountStr = PageHelper.getCellVal(cell, 20);
					cell = output.getCell(4);
					priceStr = PageHelper.getCellVal(cell, 20);
					cell = output.getCell(5);
					mark = PageHelper.getCellVal(cell, 50);
					BigDecimal amount = new BigDecimal(0);
					BigDecimal price = new BigDecimal(0);

					try {
						if (amountStr != null && !amountStr.equals("")) {
							amount = new BigDecimal(amountStr);
						}
					} catch (Exception arg41) {
						;
					}

					try {
						if (priceStr != null && !priceStr.equals("")) {
							price = new BigDecimal(priceStr);
						}
					} catch (Exception arg40) {
						;
					}

					if (amount.compareTo(zero) != 0
							&& price.compareTo(zero) != 0) {
						Product p = this.productDao.get(productCode, true);
						if (p != null) {
							Element pro = root.addElement("pro");
							Element proId = pro.addElement("pro_id");
							proId.setText(String.valueOf(p.getId()));
							Element proCode = pro.addElement("pro_code");
							proCode.setText(p.getProductCode());
							Element proName = pro.addElement("pro_name");
							proName.setText(p.getProductName());
							Element proUnit = pro.addElement("pro_unit");
							proUnit.setText(p.getUnit());
							Element proAmount = pro.addElement("pro_amount");
							proAmount.setText(amount.toString());
							Element proPrice = pro.addElement("pro_price");
							proPrice.setText(price.toString());
							Element proMark = pro.addElement("pro_mark");
							proMark.setText(mark);
						}
					}
				}
			}
		} catch (Exception arg42) {
			alertMsg = "导入错误：" + arg42.getMessage();
			Element out = root.addElement("alert_msg");
			out.setText(alertMsg);
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception arg39) {
				;
			}

		}

		response.setContentType("text/xml");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		OutputFormat arg44 = OutputFormat.createPrettyPrint();
		arg44.setEncoding("utf-8");
		ServletOutputStream arg46 = response.getOutputStream();
		XMLWriter arg47 = new XMLWriter(arg46, arg44);
		arg47.write(doc);
		arg46.flush();
		arg46.close();
		return null;
	}

	public ModelAndView handleListForStoc(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForStocView);
		String searchKey = request.getParameter("search_key");
		String type = request.getParameter("type");
		String tsId = request.getParameter("ts_id");
		if (type != null && type.equals("BUY")) {
			if (!EncCommonHelper.checkPrivilege(request, "PURC_BUY_STOC")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null && type.equals("BACK")
				&& !EncCommonHelper.checkPrivilege(request, "PURC_BACK_STOC")) {
			throw new PermissionDennyException("Permission Denny");
		}

		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (tsId == null || tsId.equals("")) {
			tsId = String.valueOf(ub.getUser().getDfTsId());
		}

		List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
		long managerId = 0L;
		if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
			managerId = ub.getStaffer().getId();
		}

		Date allowStart = null;
		if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
			allowStart = EncCommonHelper.getEarlDataDate(request);
		}

		int perPageNum = EncCommonHelper.getPageSize(request);
		int total = this.purchaseBillDao.getListForStocCount(type, searchKey,
				false, Long.parseLong(tsId), managerId, ub, allowStart);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
				perPageNum);
		int startIndex = (pageno - 1) * perPageNum;
		List list = this.purchaseBillDao.getListForStoc(type, searchKey, false,
				Long.parseLong(tsId), managerId, ub, allowStart, startIndex,
				perPageNum);
		List arr = this.parsePurchaseBill(list);
		mv.addObject("qr", EncCommonHelper.parseQueryResult(arr, total,
				perPageNum, pageno));
		mv.addObject("storehouseList", this.storehouseDao.getList(false));
		mv.addObject("searchKey", searchKey);
		mv.addObject("type", type);
		mv.addObject("tsId", tsId);
		mv.addObject("tsList", tsList);
		return mv;
	}

	public ModelAndView handleInfoForStoc(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForStocView);
		String id = request.getParameter("id");
		this.getPurchaseBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForUnStoc(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForUnStocView);
		String searchKey = request.getParameter("search_key");
		String type = request.getParameter("type");
		String tsId = request.getParameter("ts_id");
		if (type != null && type.equals("BUY")) {
			if (!EncCommonHelper.checkPrivilege(request, "PURC_BUY_UN_STOC")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null
				&& type.equals("BACK")
				&& !EncCommonHelper
						.checkPrivilege(request, "PURC_BACK_UN_STOC")) {
			throw new PermissionDennyException("Permission Denny");
		}

		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (tsId == null || tsId.equals("")) {
			tsId = String.valueOf(ub.getUser().getDfTsId());
		}

		List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
		long managerId = 0L;
		if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
			managerId = ub.getStaffer().getId();
		}

		Date allowStart = null;
		if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
			allowStart = EncCommonHelper.getEarlDataDate(request);
		}

		int perPageNum = EncCommonHelper.getPageSize(request);
		int total = this.purchaseBillDao.getListForStocCount(type, searchKey,
				true, Long.parseLong(tsId), managerId, ub, allowStart);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
				perPageNum);
		int startIndex = (pageno - 1) * perPageNum;
		List list = this.purchaseBillDao.getListForStoc(type, searchKey, true,
				Long.parseLong(tsId), managerId, ub, allowStart, startIndex,
				perPageNum);
		List arr = this.parsePurchaseBill(list);
		mv.addObject("qr", EncCommonHelper.parseQueryResult(arr, total,
				perPageNum, pageno));
		mv.addObject("storehouseList", this.storehouseDao.getList(false));
		mv.addObject("searchKey", searchKey);
		mv.addObject("type", type);
		mv.addObject("tsId", tsId);
		mv.addObject("tsList", tsList);
		return mv;
	}

	public ModelAndView handleInfoForUnStoc(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForUnStocView);
		String id = request.getParameter("id");
		this.getPurchaseBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleStoc(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String idStr = request.getParameter("id_str");
		String flag = request.getParameter("flag");
		boolean stoc = false;
		if (flag != null && flag.equals("1")) {
			stoc = true;
		}

		String[] arr = idStr.split(";");
		boolean num = false;
		String msg;
		byte arg20;
		if (!stoc) {
			try {
				for (int se = 0; se < arr.length; ++se) {
					this.purchaseBillService.txUnStoc(request,
							Long.parseLong(arr[se]), this.purchaseBillItemDao,
							this.stockDao, this.stockBalanceDao,
							this.idGenerator, ub);
				}

				msg = "保存成功";
			} catch (StockNoEnoughException arg17) {
				msg = arg17.getMessage();
			} catch (NotAllowException arg18) {
				msg = arg18.getMessage();
			} catch (CannotAcquireLockException arg19) {
				msg = "事务冲突故障，请重新操作。";
			}

			arg20 = 1;
		} else {
			try {
				String arg21 = request.getParameter("date_str");
				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				Date stocDate = sf.parse(arg21);

				for (int i = 0; i < arr.length; ++i) {
					this.purchaseBillService.txStoc(request,
							Long.parseLong(arr[i]), stocDate,
							this.purchaseBillItemDao, this.stockDao,
							this.stockBalanceDao, this.idGenerator, ub);
				}

				msg = "保存成功";
			} catch (StockNoEnoughException arg14) {
				msg = arg14.getMessage();
			} catch (NotAllowException arg15) {
				msg = arg15.getMessage();
			} catch (CannotAcquireLockException arg16) {
				msg = "事务冲突故障，请重新操作。";
			}

			arg20 = 1;
		}

		mv.addObject("returnValue", String.valueOf(arg20));
		EncCommonHelper.setAlertMessage(request, msg);
		return mv;
	}

	public ModelAndView handleAppList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "PURC_BUY_SEAR")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("est_name");
				json = request.getParameter("start_date");
				String out = request.getParameter("end_date");
				String billType = request.getParameter("bill_type");
				String exam = request.getParameter("exam");
				String paie = request.getParameter("paie");
				String tsIdStr = request.getParameter("ts_id");
				String orde = request.getParameter("orde");
				String showPrev = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long mngId = 0L;
				long tsId = 0L;
				if (tsIdStr != null && !tsIdStr.equals("")) {
					tsId = Long.parseLong(tsIdStr);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mngId = ub.getStaffer().getId();
				}

				Date allowStart = null;
				Date startDate = null;
				Date endDate = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				if (json != null && !json.equals("")) {
					startDate = sf.parse(json);
				}

				if (out != null && !out.equals("")) {
					endDate = sf.parse(EncCommonHelper.getNextDateStr(out,
							"yyyy-MM-dd"));
				}

				if (startDate == null) {
					startDate = allowStart;
				} else if (allowStart != null && allowStart.after(startDate)) {
					startDate = allowStart;
				}

				if (orde == null || orde.equals("")) {
					orde = "PURC_DATE";
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				BigDecimal remCost = new BigDecimal(0);
				List list = this.purchaseBillDao.getAppListCount(startDate,
						endDate, mapper, billType, exam, paie, tsId, ub, mngId);

				int perPageNum;
				for (perPageNum = 0; perPageNum < list.size(); ++perPageNum) {
					Object[] pageno = (Object[]) list.get(perPageNum);
					if (pageno[3] != null) {
						total += Integer.parseInt(pageno[0].toString());
						if (pageno[3].toString().equals("BUY")) {
							cost = cost.add((BigDecimal) pageno[1]);
							remCost = remCost.add((BigDecimal) pageno[2]);
						} else {
							cost = cost.subtract((BigDecimal) pageno[1]);
							remCost = remCost.subtract((BigDecimal) pageno[2]);
						}
					}
				}

				map.put("cost", cost);
				map.put("remCost", remCost);
				map.put("total", Integer.valueOf(total));
				perPageNum = EncCommonHelper.getPageSize(request);
				int arg41 = EncCommonHelper.getCurrentPageIndex(request, total,
						perPageNum);
				if (total > arg41 * perPageNum) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (showPrev != null && showPrev.equals("Y")) {
					list = this.purchaseBillDao.getAppList(startDate, endDate,
							mapper, billType, exam, paie, tsId, ub, mngId,
							orde, 0, arg41 * perPageNum);
				} else {
					list = this.purchaseBillDao.getAppList(startDate, endDate,
							mapper, billType, exam, paie, tsId, ub, mngId,
							orde, (arg41 - 1) * perPageNum, perPageNum);
				}

				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					HashMap tsItems = new HashMap();
					Object[] i = (Object[]) list.get(tmpList);
					PurchaseBill item = (PurchaseBill) i[0];
					String ts = (String) i[1];
					String creaTime = "";
					PurchaseBillExt be = (PurchaseBillExt) i[2];
					if (item.getCreateTime() != null) {
						creaTime = sfl.format(item.getCreateTime());
					}

					tsItems.put("billType", item.getBillType());
					tsItems.put("cost", item.getCost());
					tsItems.put(
							"remCost",
							item.getCost().add(be.getAdjustCost())
									.subtract(be.getPaiedCost()));
					tsItems.put("creaName", item.getCreaterName());
					tsItems.put("creaTime", creaTime);
					tsItems.put("estName", ts);
					tsItems.put("id", Long.valueOf(item.getId()));
					tsItems.put("date", sf.format(item.getPurchaseDate()));
					tsItems.put("cont", PageHelper.parseNull(item.getContent()));
					if (be.getPaied().equals("Y")) {
						tsItems.put("stat", "PAIE");
					} else if (be.getExamined().equals("Y")) {
						tsItems.put("stat", "EXAM");
					} else {
						tsItems.put("stat", "UNEXAM");
					}

					items.add(tsItems);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg42 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg43 = new ArrayList();

					for (int arg44 = 0; arg44 < arg42.size(); ++arg44) {
						HashMap arg45 = new HashMap();
						TallySet arg46 = (TallySet) arg42.get(arg44);
						arg45.put("id", Long.valueOf(arg46.getId()));
						arg45.put("name", arg46.getTitle());
						arg43.add(arg45);
					}

					map.put("tsItems", arg43);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg38) {
				map.put("status", "ERROR");
				map.put("errMsg", arg38.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg39 = new ObjectMapper();
		json = arg39.writeValueAsString(map);
		ServletOutputStream arg40 = response.getOutputStream();
		arg40.write(json.getBytes("utf-8"));
		arg40.flush();
		arg40.close();
		return null;
	}

	public ModelAndView handleAppInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();

		try {
			long mapper = Long.parseLong(request.getParameter("id"));
			PurchaseBill out = (PurchaseBill) this.purchaseBillDao.get(
					PurchaseBill.class, mapper);
			PurchaseBillExt be = (PurchaseBillExt) this.purchaseBillDao.get(
					PurchaseBillExt.class, mapper);
			List itemList = this.purchaseBillItemDao.getList(mapper);
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			String bankName = "";
			String estName = "";
			String tsName = "";
			String creaTime = "";
			String storName = "";
			if (out.getBankAccountId() != 0L) {
				BankAccount est = (BankAccount) this.purchaseBillDao.get(
						BankAccount.class, out.getBankAccountId());
				if (est != null) {
					bankName = est.getBankName();
					if (est.getAccountName() != null
							&& !est.getAccountName().equals("")) {
						bankName = bankName + "(" + est.getAccountName() + ")";
					}
				}
			}

			if (out.getStorehouseId() != 0L) {
				Storehouse arg30 = (Storehouse) this.purchaseBillDao.get(
						Storehouse.class, out.getStorehouseId());
				if (arg30 != null) {
					storName = arg30.getStoName();
				}
			}

			Establishment arg31 = (Establishment) this.purchaseBillDao.get(
					Establishment.class, out.getProviderId());
			if (arg31 != null) {
				estName = arg31.getEstName();
			}

			TallySet ts = (TallySet) this.purchaseBillDao.get(TallySet.class,
					out.getTallySetId());
			if (ts != null) {
				tsName = ts.getTitle();
			}

			if (out.getCreateTime() != null) {
				creaTime = sfl.format(out.getCreateTime());
			}

			map.put("billType", out.getBillType());
			map.put("cost", out.getCost());
			map.put("impr", out.getImprest());
			map.put("ba", bankName);
			map.put("st", storName);
			map.put("code", out.getBillCode());
			map.put("cont", out.getContent());
			map.put("creaName", out.getCreaterName());
			map.put("creaTime", creaTime);
			map.put("estName", estName);
			map.put("date", sf.format(out.getPurchaseDate()));
			String examName = "";
			String examTime = "";
			if (be.getExamined().equals("Y")) {
				examName = be.getExaminerName();
				if (be.getExamineTime() != null) {
					examTime = sfl.format(be.getExamineTime());
				}
			}

			map.put("exam", be.getExamined());
			map.put("examName", examName);
			map.put("examTime", examTime);
			map.put("tsName", tsName);
			ArrayList items = new ArrayList();
			BigDecimal itemTotal = new BigDecimal(0);

			for (int i = 0; i < itemList.size(); ++i) {
				HashMap item = new HashMap();
				String prodName = "";
				String prodCode = "";
				PurchaseBillItem bi = (PurchaseBillItem) itemList.get(i);
				Product p = (Product) this.purchaseBillDao.get(Product.class,
						bi.getProductId());
				if (p != null) {
					prodName = p.getProductName();
					prodCode = p.getProductCode();
				}

				item.put("prodName", prodName);
				item.put("prodCode", prodCode);
				item.put("amou", bi.getAmount());
				item.put("pric", bi.getUnitPrice());
				item.put("cost", bi.getCost());
				item.put("mark", PageHelper.parseNull(bi.getMark()));
				items.add(item);
				itemTotal = itemTotal.add(bi.getCost());
			}

			map.put("itemTotal", itemTotal);
			map.put("items", items);
			map.put("status", "OK");
			map.put("errMsg", "");
		} catch (Exception arg27) {
			map.put("status", "ERROR");
			map.put("errMsg", arg27.toString());
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg28 = new ObjectMapper();
		String json = arg28.writeValueAsString(map);
		ServletOutputStream arg29 = response.getOutputStream();
		arg29.write(json.getBytes("utf-8"));
		arg29.flush();
		arg29.close();
		return null;
	}

	public ModelAndView handleAppListForExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String sk = request.getParameter("sk");
		String tsIdStr = request.getParameter("ts_id");
		String showPrev = request.getParameter("show_prev");
		String initQuer = request.getParameter("init_quer");
		String billType = request.getParameter("bill_type");
		String privCode = "PURC_BUY_EXAM";
		if (billType != null && billType.equals("BACK")) {
			privCode = "PURC_BACK_EXAM";
		}

		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, privCode)) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				long mapper = 0L;
				long out = 0L;
				if (tsIdStr != null && !tsIdStr.equals("")) {
					out = Long.parseLong(tsIdStr);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mapper = ub.getStaffer().getId();
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				int total = 0;
				BigDecimal cost = new BigDecimal(0);
				List list = this.purchaseBillDao.getAppListForExamCount(
						billType, sk, out, ub, allowStart, mapper);
				if (list != null && !list.isEmpty() && list.get(0) != null) {
					Object[] perPageNum = (Object[]) list.get(0);
					if (perPageNum[1] != null) {
						total = Integer.parseInt(perPageNum[0].toString());
						cost = (BigDecimal) perPageNum[1];
					}
				}

				map.put("cost", cost);
				map.put("total", Integer.valueOf(total));
				int arg33 = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, arg33);
				if (total > pageno * arg33) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (showPrev != null && showPrev.equals("Y")) {
					list = this.purchaseBillDao.getAppListForExam(billType, sk,
							out, ub, allowStart, mapper, 0, pageno * arg33);
				} else {
					list = this.purchaseBillDao.getAppListForExam(billType, sk,
							out, ub, allowStart, mapper, (pageno - 1) * arg33,
							arg33);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					Object[] tsItems = (Object[]) list.get(tmpList);
					PurchaseBill i = (PurchaseBill) tsItems[0];
					String item = (String) tsItems[1];
					String ts = "";
					if (i.getCreateTime() != null) {
						ts = sfl.format(i.getCreateTime());
					}

					HashMap item1 = new HashMap();
					item1.put("cost", i.getCost());
					item1.put("creaName", i.getCreaterName());
					item1.put("creaTime", ts);
					item1.put("estName", item);
					item1.put("id", Long.valueOf(i.getId()));
					item1.put("date", sf.format(i.getPurchaseDate()));
					items.add(item1);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg34 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg35 = new ArrayList();

					for (int arg36 = 0; arg36 < arg34.size(); ++arg36) {
						HashMap arg37 = new HashMap();
						TallySet arg38 = (TallySet) arg34.get(arg36);
						arg37.put("id", Long.valueOf(arg38.getId()));
						arg37.put("name", arg38.getTitle());
						arg35.add(arg37);
					}

					map.put("tsItems", arg35);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg30) {
				map.put("status", "ERROR");
				map.put("errMsg", arg30.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg31 = new ObjectMapper();
		String json = arg31.writeValueAsString(map);
		ServletOutputStream arg32 = response.getOutputStream();
		arg32.write(json.getBytes("utf-8"));
		arg32.flush();
		arg32.close();
		return null;
	}

	public ModelAndView handleAppListForUnExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String sk = request.getParameter("sk");
		String tsIdStr = request.getParameter("ts_id");
		String showPrev = request.getParameter("show_prev");
		String initQuer = request.getParameter("init_quer");
		String billType = request.getParameter("bill_type");
		String privCode = "PURC_BUY_UN_EXAM";
		if (billType != null && billType.equals("BACK")) {
			privCode = "PURC_BACK_UN_EXAM";
		}

		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, privCode)) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				long mapper = 0L;
				long out = 0L;
				if (tsIdStr != null && !tsIdStr.equals("")) {
					out = Long.parseLong(tsIdStr);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mapper = ub.getStaffer().getId();
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				int total = this.purchaseBillDao.getAppListForUnExamCount(
						billType, sk, out, ub, allowStart, mapper);
				int perPageNum = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, perPageNum);
				if (total > pageno * perPageNum) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				List list;
				if (showPrev != null && showPrev.equals("Y")) {
					list = this.purchaseBillDao.getAppListForUnExam(billType,
							sk, out, ub, allowStart, mapper, 0, pageno
									* perPageNum);
				} else {
					list = this.purchaseBillDao.getAppListForUnExam(billType,
							sk, out, ub, allowStart, mapper, (pageno - 1)
									* perPageNum, perPageNum);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					Object[] tsItems = (Object[]) list.get(tmpList);
					PurchaseBill i = (PurchaseBill) tsItems[0];
					String item = (String) tsItems[1];
					HashMap ts = new HashMap();
					ts.put("cost", i.getCost());
					ts.put("examName", tsItems[2]);
					ts.put("examTime", sfl.format((Date) tsItems[3]));
					ts.put("estName", item);
					ts.put("id", Long.valueOf(i.getId()));
					ts.put("date", sf.format(i.getPurchaseDate()));
					items.add(ts);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg31 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg32 = new ArrayList();

					for (int arg33 = 0; arg33 < arg31.size(); ++arg33) {
						HashMap arg34 = new HashMap();
						TallySet arg35 = (TallySet) arg31.get(arg33);
						arg34.put("id", Long.valueOf(arg35.getId()));
						arg34.put("name", arg35.getTitle());
						arg32.add(arg34);
					}

					map.put("tsItems", arg32);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg28) {
				map.put("status", "ERROR");
				map.put("errMsg", arg28.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg29 = new ObjectMapper();
		String json = arg29.writeValueAsString(map);
		ServletOutputStream arg30 = response.getOutputStream();
		arg30.write(json.getBytes("utf-8"));
		arg30.flush();
		arg30.close();
		return null;
	}

	public ModelAndView handleAppExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String status = "";
		String errMsg = "";
		if (ub == null) {
			status = "NO_LOGIN";
		} else {
			String map = request.getParameter("type");
			String mapper = request.getParameter("id");
			if (map != null && map.equals("UNEXAM")) {
				try {
					this.purchaseBillService.txUnExamine(request,
							Long.parseLong(mapper), this.purchaseBillDao,
							this.purchaseBillItemDao,
							this.bankAccountBalanceDao,
							this.bankAccountDetailDao, this.stockDao,
							this.stockBalanceDao, this.idGenerator,
							this.financeDetailDao, ub);
					status = "OK";
				} catch (CannotAcquireLockException arg12) {
					status = "ERROR";
					errMsg = "事务冲突故障，请重新操作！";
				} catch (NotAllowException arg13) {
					status = "ERROR";
					errMsg = arg13.getMessage();
				}
			} else {
				try {
					this.purchaseBillService.txExamine(request,
							Long.parseLong(mapper), this.purchaseBillDao,
							this.purchaseBillItemDao, this.payBillDao,
							this.adjustBillDao, this.bankAccountBalanceDao,
							this.stockDao, this.stockBalanceDao,
							this.idGenerator, ub);
					status = "OK";
				} catch (NotAllowException arg10) {
					status = "ERROR";
					errMsg = arg10.getMessage();
				} catch (CannotAcquireLockException arg11) {
					status = "ERROR";
					errMsg = "事务冲突故障，请重新操作！";
				}
			}
		}

		HashMap map1 = new HashMap();
		map1.put("status", status);
		map1.put("errMsg", errMsg);
		ObjectMapper mapper1 = new ObjectMapper();
		String json = mapper1.writeValueAsString(map1);
		ServletOutputStream out = response.getOutputStream();
		out.write(json.getBytes("utf-8"));
		out.flush();
		out.close();
		return null;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public StockDao getStockDao() {
		return this.stockDao;
	}

	public void setStockDao(StockDao stockDao) {
		this.stockDao = stockDao;
	}

	public DataSource getDataSource() {
		return this.dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public QueryDao getQueryDao() {
		return this.queryDao;
	}

	public void setQueryDao(QueryDao queryDao) {
		this.queryDao = queryDao;
	}

	public StockBalanceDao getStockBalanceDao() {
		return this.stockBalanceDao;
	}

	public void setStockBalanceDao(StockBalanceDao stockBalanceDao) {
		this.stockBalanceDao = stockBalanceDao;
	}

	public StorehouseDao getStorehouseDao() {
		return this.storehouseDao;
	}

	public void setStorehouseDao(StorehouseDao storehouseDao) {
		this.storehouseDao = storehouseDao;
	}

	public BankAccountBalanceDao getBankAccountBalanceDao() {
		return this.bankAccountBalanceDao;
	}

	public void setBankAccountBalanceDao(
			BankAccountBalanceDao bankAccountBalanceDao) {
		this.bankAccountBalanceDao = bankAccountBalanceDao;
	}

	public BankAccountDao getBankAccountDao() {
		return this.bankAccountDao;
	}

	public void setBankAccountDao(BankAccountDao bankAccountDao) {
		this.bankAccountDao = bankAccountDao;
	}

	public BankAccountDetailDao getBankAccountDetailDao() {
		return this.bankAccountDetailDao;
	}

	public void setBankAccountDetailDao(
			BankAccountDetailDao bankAccountDetailDao) {
		this.bankAccountDetailDao = bankAccountDetailDao;
	}

	public String getInfoForPrintView() {
		return this.infoForPrintView;
	}

	public void setInfoForPrintView(String infoForPrintView) {
		this.infoForPrintView = infoForPrintView;
	}

	public AdjustBillDao getAdjustBillDao() {
		return this.adjustBillDao;
	}

	public void setAdjustBillDao(AdjustBillDao adjustBillDao) {
		this.adjustBillDao = adjustBillDao;
	}

	public PayBillDao getPayBillDao() {
		return this.payBillDao;
	}

	public void setPayBillDao(PayBillDao payBillDao) {
		this.payBillDao = payBillDao;
	}

	public String getCountSearchResultView() {
		return this.countSearchResultView;
	}

	public void setCountSearchResultView(String countSearchResultView) {
		this.countSearchResultView = countSearchResultView;
	}

	public String getDetailSearchResultView() {
		return this.detailSearchResultView;
	}

	public void setDetailSearchResultView(String detailSearchResultView) {
		this.detailSearchResultView = detailSearchResultView;
	}

	public ProductTypeDao getProductTypeDao() {
		return this.productTypeDao;
	}

	public void setProductTypeDao(ProductTypeDao productTypeDao) {
		this.productTypeDao = productTypeDao;
	}

	public String getListForAccountView() {
		return this.listForAccountView;
	}

	public void setListForAccountView(String listForAccountView) {
		this.listForAccountView = listForAccountView;
	}

	public String getListForPayView() {
		return this.listForPayView;
	}

	public void setListForPayView(String listForPayView) {
		this.listForPayView = listForPayView;
	}

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public String getListForAccountFormView() {
		return this.listForAccountFormView;
	}

	public void setListForAccountFormView(String listForAccountFormView) {
		this.listForAccountFormView = listForAccountFormView;
	}

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}

	public FinanceDetailDao getFinanceDetailDao() {
		return this.financeDetailDao;
	}

	public void setFinanceDetailDao(FinanceDetailDao financeDetailDao) {
		this.financeDetailDao = financeDetailDao;
	}

	public String getItemListForEstablishmentView() {
		return this.itemListForEstablishmentView;
	}

	public void setItemListForEstablishmentView(
			String itemListForEstablishmentView) {
		this.itemListForEstablishmentView = itemListForEstablishmentView;
	}
}